package com.mpsc.multi.source.config.transaction;

import com.mpsc.multi.source.config.datasource.DataSourceContextHolder;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.apache.ibatis.transaction.Transaction;
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;

import javax.sql.DataSource;

public class MultiDataSourceTransactionFactory extends SpringManagedTransactionFactory {
    @Override
    public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
        DataSourceContextHolder.setDB(DataSourceContextHolder.DEFAULT_DS);
        return new MultiDataSourceTransaction(dataSource);
    }
}
